<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    @include('common-css')
    <style>

        .input_box {
            width: 100%;
            height: 40px;
            margin-top: 15px;
            margin-bottom: 15px;
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }

        .input_label {
            width: 120px;
            box-sizing: border-box;
        }

        .project-table {
            margin-top: 15px;
        }

        .status-tag {
            color: #1890ff;
            border: 1px solid #91d5ff;
            border-radius: 3px;
            background: #e6f7ff;
            font-size: 12px;
            padding: 2px 3px;
        }

        .ant-table-tbody > tr > td, .ant-table-thead > tr > th {
            vertical-align: middle;
            line-height: 25px;
        }

        .search_box {
            width: 1000px;
        }

        .search_box input {
            width: 300px;
        }

        .search_box button {
            margin-left: 20px;
        }

        .search_box .ant-select {
            margin-left: 20px;
        }
    </style>
</head>
<body>

<div id="app"></div>

<script id="appTemplate" type="x-template">
    <a-locale-provider :locale="antdLocale">
        <div class="container">

            @include('meeting-review.header-tpl')

            <main style="overflow: scroll">
                <a-table class="project-table"
                         rowKey="project_id"
                         size="small"
                         :columns="projectTableColumns"
                         :dataSource="filteredProjects"
                         :loading="loadingPageData"
                         :pagination="{pageSize: 10000, hideOnSinglePage: true, position: 'both', showTotal: total => `共 ${total} 项`}">
                    <span slot="award" slot-scope="text, record">
                        @{{ record.award ? record.award : '未获奖' }}
                    </span>
                    <span slot="application_form" size="large" slot-scope="text, record">
                        <a :href="'/home/view-form?id=' + record.project_id" target="_blank">查看</a>
                    </span>
                    <span slot="attachments" slot-scope="text, record">
                        <a :href="'/home/view-attachments?project_id=' + record.project_id" target="_blank">
                            <span>查看</span>
                        </a>
                    </span>
                    <span slot="score_time_costs" size="large" slot-scope="text, record">
                        <template v-for="reviewer_score in record.score_per_reviewer">
                            <span v-html="formatScoreTimeCost(reviewer_score.score_time_cost)"/><br>
                        </template>
                    </span>
                    <span slot="reviewer_scores" size="large" slot-scope="text, record">
                        <template v-for="reviewer_score in record.score_per_reviewer">
                            <span>@{{ reviewer_score.score !== null ? reviewer_score.score : '-' }}</span><br>
                        </template>
                        <label v-if="!record.scores_normal"
                               style="color: red;">@{{ record.scores_desc }}</label>
                    </span>
                    <span slot="is_evidence_material_valid" size="large" slot-scope="text, record">
                        <template v-for="reviewer_score in record.score_per_reviewer">
                            <label>@{{ reviewer_score.is_evidence_material_valid === null ? '-' :
                                (reviewer_score.is_evidence_material_valid === 1 ? '是' : '否') }}</label>
                            <br>
                        </template>
                    </span>
                    <span slot="reviewer_remarks" size="large" slot-scope="text, record">
                        <template v-for="reviewer_score in record.score_per_reviewer">
                            <a-textarea :disabled="true" :autosize="{minRows: 1, maxRows: 10}"
                                        v-model="reviewer_score.remark"/>
                            <br>
                        </template>
                    </span>
                    <span slot="avg_score" size="large" slot-scope="text, record">
                        @{{ record.avg_score !== null ? record.avg_score : '-' }}
                    </span>
                    {{--                            <span slot="score_status" size="large" slot-scope="text, record">--}}
                    {{--                                @{{ record.score_status_phrase }}--}}
                    {{--                                <template v-if="record.score_status == SCORE_STATUS_LEADER_REVIEW_REJECTED">--}}
                    {{--                                    <br>(@{{ record.large_group_leader_review_remark }})--}}
                    {{--                                </template>--}}
                    {{--                            </span>--}}
                    <span slot="meeting_review_status" size="large" slot-scope="text, record">
                                <template v-if="record.toMeetingReview">
                                    <span v-if="atPhaseMeetingReview">
{{--                                        @{{ REVIEW_STATUS_TO_REVIEW }}--}}
                                        待评审
                                    </span>
                                    <span v-else>
                                        评审完成
                                    </span>
                                </template>
                                <template v-else>
                                     @{{ record.meeting_review_status }}
                                    <template v-if="record.meeting_review_remark">
                                        <br>(@{{ record.meeting_review_remark }})
                                    </template>
                                </template>
                            </span>
                </a-table>
            </main>
        </div>
    </a-locale-provider>
</script>

@include('common-js')
@include('meeting-review.header-js')

<script>
    var queryParams = parseUrl(location.href).params;
    var awardsInfo = {!! json_encode(array_values(config('vars.awards')), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) !!};

    var projectTableColumns = [
        // {
        //     width: 40,
        //     title: '序号',
        //     dataIndex: 'num',
        // },
        // {
        //     width: 60,
        //     title: '名次',
        //     dataIndex: 'meeting_ranking',
        //     scopedSlots: {
        //         customRender: 'meeting_ranking'
        //     }
        // },
        {
            width: 60,
            title: '网评名次',
            dataIndex: 'meeting_initial_ranking'
        },
        {
            width: 80,
            title: '获奖',
            scopedSlots: {
                customRender: 'award'
            }
        },
        {
            width: 150,
            title: '项目名称',
            dataIndex: 'project_name',
        },
        {
            width: 100,
            title: '申报者',
            dataIndex: 'applicant',
        },
        {
            width: 60,
            title: '申报书',
            dataIndex: 'application_form',
            scopedSlots: {
                customRender: 'application_form'
            }
        },
        {
            width: 60,
            title: '附件',
            dataIndex: 'attachments',
            scopedSlots: {
                customRender: 'attachments'
            }
        },
        // {
        //     width: 100,
        //     title: '评分时长',
        //     dataIndex: 'score_time_costs',
        //     scopedSlots: {
        //         customRender: 'score_time_costs'
        //     }
        // },
        // {
        //     width: 70,
        //     title: '专家评分',
        //     dataIndex: 'reviewer_scores',
        //     scopedSlots: {
        //         customRender: 'reviewer_scores'
        //     }
        // },
        // {
        //     width: 70,
        //     title: '附件证明材料是否真实有效',
        //     dataIndex: 'is_evidence_material_valid',
        //     scopedSlots: {
        //         customRender: 'is_evidence_material_valid'
        //     }
        // },
        // {
        //     width: 200,
        //     title: '专家意见',
        //     dataIndex: 'reviewer_remarks',
        //     scopedSlots: {
        //         customRender: 'reviewer_remarks'
        //     }
        // },
        // {
        //     width: 60,
        //     title: '平均分',
        //     dataIndex: 'avg_score',
        //     scopedSlots: {
        //         customRender: 'avg_score'
        //     }
        // },
        // {
        //     width: 80,
        //     title: '网评状态',
        //     dataIndex: 'score_status',
        //     scopedSlots: {
        //         customRender: 'score_status'
        //     }
        // },
        {
            width: 80,
            title: '会评状态',
            key: 'meeting_review_status',
            scopedSlots: {
                customRender: 'meeting_review_status'
            }
        },
        // {
        //     width: 100,
        //     title: '操作',
        //     key: 'operations',
        //     scopedSlots: {
        //         customRender: 'operations'
        //     }
        // }
    ];
</script>

<script>
    var app = new Vue({
        el: '#app',
        template: '#appTemplate',
        data: {
            profCategoryFilter: '',
            searchKeyword: '',

            projectTableColumns,
            pageData: [],
            projectsCount:0,
            loadingPageData: false,

            rankChangeProcess:false,
            rankChangeItem:0,

            awards_configure:[
                {
                    key:1,
                    number:0,
                    title:'一等奖'
                }
            ],
            awardsType:0,
            setAwardsDialog:false,
            setAwardsMode:'number',
            setNumPlaceholder:'',
            awardsNum:0,
            awardsNumMax:100,
            awardsCount:0,
            awardsRatio:0,
            confirmLoading:false,

            editRankProjectId:0,

            largeGroupId: -1,
            maxAwardRate: 50,

            // 项目的专家组评分状态
            SCORE_STATUS_TO_SCORE: 1,
            SCORE_STATUS_ABNORMAL_SCORES: 2,
            SCORE_STATUS_TO_LEADER_REVIEW: 3,
            SCORE_STATUS_LEADER_REVIEW_PASSED: 4,
            SCORE_STATUS_LEADER_REVIEW_REJECTED: 5,

            LEADER_REVIEW_RESULT_PASSED: '通过',
            LEADER_REVIEW_RESULT_REJECTED: '不通过',

            REVIEW_STATUS_TO_REVIEW: '待评审',
            REVIEW_STATUS_PASSED: '通过',
            REVIEW_STATUS_REJECTED: '不通过',

            queryParams,
            awardsInfo,
            profCategories,

            asideSelectedKeys:
                queryParams.aside_key ? [queryParams.aside_key] : [],
            antdLocale:
            antd.locales.zh_CN,

            ...MeetingReviewHeader.data,
            ...Workflow.data,
        },
        computed: {
            atPhaseMeetingReview() {
                return this.atPhases(['E'], this.largeGroupId)
            },
            notAtPhaseMeetingReview() {
                return !this.atPhaseMeetingReview
            },
            filteredProjects() {
                var projects = this.searchFilteredProjects;
                if (this.profCategoryFilter) {
                    projects = projects.filter(project => {
                        return project.prof_category == this.profCategoryFilter
                    })
                }
                var num = 1;
                projects.forEach(project => {
                    project.num = num++
                });
                return projects
            },
            searchFilteredProjects() {
                var projects;
                if (this.searchKeyword) {
                    var q = this.searchKeyword.trim();
                    projects = this.pageData.filter(project => {
                        var text = project.project_name + project.applicant + project.project_name + project.avg_score;
                        return text.toLowerCase().indexOf(q) != -1
                    })
                } else {
                    projects = this.pageData
                }
                return projects
            },
        },
        mounted() {
            this.reloadPageData();
            this.reloadWorkflowPhases()
        },
        methods: {
            isMeetingReviewValid(project) {
                let reviewStatus = project.meeting_review_status
                if (reviewStatus !== this.REVIEW_STATUS_PASSED && reviewStatus !== this.REVIEW_STATUS_REJECTED) {
                    return false
                }
                let reviewRemark = project.meeting_review_remark
                reviewRemark = reviewRemark ? reviewRemark.trim() : ''
                if (reviewStatus == this.REVIEW_STATUS_REJECTED && !reviewRemark) {
                    return false
                }
                return true
            },
            formatScoreTimeCost(scoreTimeCost) {
                if (scoreTimeCost === null) {
                    return '-'
                } else if (scoreTimeCost < 60) {
                    return `<span style="color: red;">${scoreTimeCost}秒</span>`
                } else if (scoreTimeCost < 3600) {
                    let minutes = parseInt(scoreTimeCost / 60);
                    let seconds = scoreTimeCost % 60;
                    let content = `${minutes}分钟${seconds}秒`;
                    return scoreTimeCost < 300 ? `<span style="color: red;">${content}</span>` : content
                } else if (scoreTimeCost < 86400) {
                    let hours = parseInt(scoreTimeCost / 3600);
                    let minitues = Math.round(scoreTimeCost % 3600 / 60);
                    return `${hours}小时${minitues}分钟`
                } else {
                    let days = parseInt(scoreTimeCost / 86400);
                    let hours = Math.round(scoreTimeCost % 86400 / 3600);
                    return `${days}天${hours}小时`
                }
            },
            reloadPageData() {
                this.loadingPageData = true;
                axios.get('/api/meeting-review/get-projects').then(response => {
                    let data = response.data;
                    if (data.ok) {
                        if (data.projects.length < 1) {
                            warn('暂无数据')
                            this.loadingPageData = false
                            return
                        }
                        data.projects.forEach(project => project.toMeetingReview = project.meeting_review_status === this.REVIEW_STATUS_TO_REVIEW)
                        data.projects.forEach((project, i) => {
                            project.num = i + 1;
                        })
                        this.pageData = data.projects;

                        this.projectsCount = data.projects.length
                        this.awardsNumMax  = this.projectsCount
                        this.setNumPlaceholder = '入选数量(0~'+this.awardsNumMax+')'

                        this.largeGroupId = data.large_group_id;
                        this.awards_configure = data.awards_configure
                        this.awardsNum = data.awards_configure[0]['number']
                        console.log(this.awards_configure)
                    } else {
                        error('加载页面数据失败: ' + data.msg)
                    }
                    this.loadingPageData = false
                })
            },

            //调整排名
            rankChange(item){
                //排名输入虽然聚焦但是没有修改排名时不提交
                if (item.isChange !== true) {
                    return
                }
                this.rankChangeProcess = true
                this.rankChangeItem = item.project_id
                axios.post('/api/committee/set-meeting-rank',
                    {project_id:item.project_id,rank:item.meeting_ranking})
                    .then(response => {
                        let data = response.data;
                        if (data.ok) {
                            success('更新完成')
                            this.reloadPageData()
                        } else {
                            error('更新排名失败: ' + data.msg)
                        }
                        this.rankChangeProcess = false
                        //设置排名后需要重置change状态
                        item.isChange = false
                        //console.log(item.project_id)
                        //window.location.href = "#"+item.project_id;
                    })
            },

            setAwardsConfirm(){
                let error = ''
                let allCount = 0
                this.awards_configure.forEach(function (item) {
                    if (item.number == null || item.number == 0) {
                        error = '请设置'+item.title+'数量'
                    }
                    allCount += item.number
                })

                //是否存在未设置项
                if (error != '') {
                    return warn(error)
                }

                //设置奖项总数是否超过项目数量
                if (allCount > this.projectsCount) {
                    return warn('请重新配置奖项数量（不得超过会评项目总量）')
                }

                this.confirmLoading = true
                axios.post('/api/committee/set-awards-configure',
                    {configure: JSON.stringify(this.awards_configure)})
                    .then(response => {
                        let data = response.data;
                        if (data.ok) {
                            this.reloadPageData()
                            success('设置完成')
                        } else {
                            warn('设置失败: ' + data.msg)
                        }
                        this.confirmLoading = false
                        this.setAwardsDialog = false
                    })
            },


            awardsTypeChange(){
                let temp = this.awards_configure[this.awardsType]
                if (temp.number > 0) {
                    this.awardsCount = temp.number
                    this.awardsRatio = Math.ceil((temp.number / this.projectsCount) * 100)
                    this.awardsNum = temp.number
                } else {
                    this.awardsCount = 0
                    this.awardsRatio = 0
                    this.awardsNum = 0
                }
            },
            setAwardsModeChange(){
                this.setAwardsNumChange(this.awardsNum)
            },
            setAwardsNumChange(val){
                if (this.setAwardsMode == 'number') {
                    this.awardsNumMax  = this.projectsCount
                    this.setNumPlaceholder = '入选数量(0~'+this.awardsNumMax+')'
                    this.awardsCount = val
                    this.awardsRatio = Math.round((val / this.projectsCount) * 100)

                    this.awards_configure[this.awardsType].number = val
                } else {
                    this.awardsNumMax  = 100
                    this.setNumPlaceholder = '入选比例(0~100)'
                    this.awardsCount = Math.round(this.projectsCount * (val/100))
                    this.awardsRatio = val

                    this.awards_configure[this.awardsType].number = this.awardsCount
                }
            },

            ...MeetingReviewHeader.methods,
            ...Workflow.methods,
        }
    })
</script>

</body>
</html>


